package org.example.travel_web.controller.admin;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.example.travel_web.dto.PageResult;
import org.example.travel_web.dto.route.PageResp;
import org.example.travel_web.dto.route.RouteDetailResp;
import org.example.travel_web.dto.route.RoutePageReq;
import org.example.travel_web.dto.route.RouteReq;
import org.example.travel_web.entity.RouteCategoriesET;
import org.example.travel_web.service.RouteCategoriesService;
import org.example.travel_web.service.RoutesService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/routes")
@Tag(name = "路线管理")
public class RoutesController {

    @Resource
    private RoutesService routesService;
    @Resource
    private RouteCategoriesService routeCategoriesService;

    @GetMapping
    @Operation(summary = "路线分页")
    public PageResult<PageResp> pageResult(@Valid RoutePageReq req) {
        return routesService.pageResult(req);
    }

    @GetMapping("/category")
    @Operation(summary = "路线分类")
    public List<RouteCategoriesET> getCategories() {
        return routeCategoriesService.list();
    }

    @GetMapping("/{id}")
    @Operation(summary = "路线详情")
    @Parameter(name = "id", description = "路线 ID", required = true, in = ParameterIn.PATH)
    public RouteDetailResp getRouteDetail(@PathVariable Integer id) {
        return routesService.getRouteDetail(id);
    }

    @PostMapping
    @Operation(summary = "新增路线")
    public void addRoutes(@Valid RouteReq req) {
        routesService.addRoutes(req);
    }

    @PutMapping
    @Operation(summary = "修改路线")
    public void updateRoutes(@Valid RouteReq req) {
        routesService.updateRoutes(req);
    }

    @DeleteMapping
    @Operation(summary = "删除路线")
    @Parameter(name = "ids", description = "路线 ID 数组", required = true, in = ParameterIn.QUERY)
    public void deleteRoutes(@RequestParam Integer[] ids) {
        routesService.deleteRoutes(ids);
    }
}
